<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			//定义函数
			function hello()
			{
					document.write("Hello world!<br/>");
					
				
			}
			hello();
			hello();
			
			function add(a,b) //a b 实参
			{
			var result = a+b;
			return result;
				
			}
			document.write("3+5="+add(3,5)+"<br/>");
			//2.
			
			var add2 = function(a,b){
				var result = a+b;
				return result;
			}
			document.write("3+5="+add2(3,5)+"<br/>");
			//3
			var add3 = new Function("a","b","return a+b;");
			document.write("3+5="+add3(3,5)+"<br/>");
			
			//练习
			//编写一行数，传入年月日，计算返回这天一年的第几年
			document.write("2024-4-30日是这个2024年的第"+calcDay(2024,4,30)+"天");
			function calcDay(year,month,day)
			{
				var allDay = 0;
				if(month==1)
				{
				allDay = day;
	
				}else if(month==2)
				{
					
					allDay = 31+day+ruen(year);
				}else if(month==3){
					allDay = 31+28+day+ruen(year);
				}else if(month==4){
					allDay = 30+31+28+day+ruen(year);
				}else if (month==5) {
					allDay = 30+31+31+28+day+ruen(year);
				}else if(month==6){
					allDay = 31+30+31+31+28+day+ruen(year);
				}else if(month==7){
					allDay = 30+31+30+31+31+28+day+ruen(year);
				}else if(month==8){
					allDay = 31+30+31+30+31+31+28+day+ruen(year);
				}else if(month==9){
					allDay = 31+31+30+31+30+31+31+28+day+ruen(year);
				}else if(month==10){
					allDay = 30+31+31+30+31+30+31+31+28+day+ruen(year);
				}else if(month==11){
					allDay = 31+30+31+31+30+31+30+31+31+28+day+ruen(year);
				}else if(month==12){
					allDay = 30+31+30+31+31+30+31+30+31+31+28+day+ruen(year);
				}
				return allDay;
				
			}
			function ruen(year)
			{
				if((year%4==0 && year%100!==0)||(year%400==0)){
					return 1;
				}
				return 0;
			}
			
		</script>
	</body>
</html>
